package com.hzp.lolnews.ui.novel.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.ui.novel.bean.AutoPlayBean;

import java.util.List;

/**
 * Created by Administrator on 2016/10/12.
 */
public class AutoPlayAdapter extends PagerAdapter {

    private List<AutoPlayBean.DataBean.RowsBean> images;

    public AutoPlayAdapter() {
//        this.images = image;
    }

    public void setData(List<AutoPlayBean.DataBean.RowsBean> image) {
        this.images = image;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return images != null ? Integer.MAX_VALUE : 0;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        SimpleDraweeView iv = new SimpleDraweeView(container.getContext());
        iv.setScaleType(ImageView.ScaleType.FIT_XY);
        iv.setImageURI(images.get(position % images.size()).getImg());
        container.addView(iv);

//        iv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(container.getContext(), DetailActivity.class);
//                intent.putExtra("detail", images.get(position % images.size()).getLink_object().getSlug());
//                String thumb = images.get(position % images.size()).getLink_object().getThumb();
//                intent.putExtra("thumb", thumb);
//                container.getContext().startActivity(intent);
//            }
//        });
        return iv;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((SimpleDraweeView) object);
    }
}
